<?
if (!defined('IN_MEDIA_ADMIN')) die("Hacking attempt");
function acp_type(&$url) {
	$t_url = strtolower($url);
	$ext = explode('.',$t_url);
	$ext = $ext[count($ext)-1];
	$ext = explode('?',$ext);
	$ext = $ext[0];
	$movie_arr = array(
		'wmv',
		'avi',
		'asf',
		'mpg',
		'mpe',
		'mpeg',
		'asx',
		'm1v',
		'mp2',
		'mpa',
		'ifo',
		'vob',
		'smi',
	);
	
	$extra_swf_arr = array(
		'www.metacafe.com',
		'www.livevideo.com',
	);
	
	for ($i=0;$i<count($extra_swf_arr);$i++){
		if (preg_match("#^http://".$extra_swf_arr[$i]."/(.*?)#s",$url)) {
			$type = 2;
			break;
		}
	}
	$is_novamov = (preg_match("#novamov.com/video/(.*?)#s", $url));
	$is_speedyshare = (preg_match("#speedyshare.com/files/([^/]+)#",$url,$id_sr));
	$is_zippyshare = (preg_match("#zippyshare.com/v/([^/]+)#",$url,$id_sr));
	$is_vidxden = (preg_match("#vidxden.com/(.*?)#s", $url));
	$is_picas = (preg_match("#picasaweb.google.com/lh/photo/(.*?)#s", $url));
	$is_vidbux = (preg_match("#vidbux.com/([^/]+)#",$url,$id_sr));
	$is_cyworld = (preg_match("#cyworld.vn/([^/]+)#",$url,$id_sr));
	$is_seeon = (preg_match("#video.seeon.tv/([^/]+)#",$url,$id_sr));
    $is_cyworld1 = (preg_match("#http://kine.cyworld.vn/detail/(.*?)#s",$url));
	$is_cyworld2 = (preg_match("#http://www.cyworld.vn/v2/myhome/video/detail/homeid/(.*?)#s",$url));
	$is_4shared = (preg_match('#4shared.com/file/(.*?)#s', $url, $id_sr));
	$is_4shared1 = (preg_match('#4shared.com/video/(.*?)#s', $url, $id_sr));
	$is_4shared2 = (preg_match('#4shared.com/embed/(.*?)#s', $url, $id_sr));
	$is_2shared = (preg_match('#2shared.com/file/(.*?)#s', $url, $id_sr));
	$is_2shared1 = (preg_match('#2shared.com/video/(.*?)#s', $url, $id_sr));
	$is_megafun = (preg_match("#megafun.vn/([^/]+)#",$url,$id_sr));
	$is_videobb = (preg_match("#videobb.com/video/([^/]+)#",$url,$id_sr));
	$is_sharevnn = (preg_match('#share.vnn.vn/dl.php/(.*?)#s', $url, $id_sr));
	$is_nhaccuatui = (preg_match("#nhaccuatui.com(.*?)#s", $url));
	$is_movshare = (preg_match("#movshare.net/video/(.*?)#s", $url));
	$is_youtube = (preg_match("#youtube.com/watch\?v=(.*?)#s", $url,$id_sr));
	$is_youtube1 = (preg_match("#youtube.com/v/([^/]+)#",$url,$id_sr));
	$is_youtube2 = (preg_match("#youtube.com/embed/(.*?)#s", $url,$id_sr));
    $is_gdata = (preg_match("#gdata.youtube.com/feeds/playlists/(.*?)#s",$url)); 
	$is_gdatayoutube = (preg_match("#youtube.com/feeds/api/playlists/([^/]+)#",$url,$id_sr));
	$is_daily = (preg_match("#dailymotion.com#",$url));
	$is_daily1 = (preg_match("#http://www.dailymotion.com/video/(.*)#",$url)); 
	$is_vntube = (preg_match("#vntube.com/mov/view_video.php\?viewkey=(.*?)#s",$url));
	$is_tamtay = (preg_match("#video.tamtay.vn/(.*?)#s", $url));
    $is_tamtay_url1 = (preg_match("#http://www.tamtay.vn/video/play/config/(.*)#",$url));
	$is_tamtay_url2 = (preg_match("#http://tamtay.vn/video/play/config/(.*)#",$url));
	$is_chacha = (preg_match("#chacha.vn/song/(.*?)#s",$url));
	$is_clipvn = (preg_match('#clip.vn/watch/(.*?)#s',$url));
	$is_clipvn1 = (preg_match("#clip.vn/w/(.*?)#s",$url));	
	$is_googleVideo = (preg_match("#video.google.com/videoplay\?docid=(.*?)#s",$url));
	$is_googleVideo1 = (preg_match("#http://video.google.com/googleplayer.swf?docId=(.*?)#s",$url));
	$is_myspace = (preg_match("#http://vids.myspace.com/index.cfm\?fuseaction=vids.individual&VideoID=(.*?)#s",$url));
	$is_videozer = (preg_match("#videozer.com/embed/(.*?)#s", $url, $id_sr));
	$is_videozer1 = (preg_match('#videozer.com/video/(.*?)#s', $url, $id_sr));
	$is_timnhanh = (preg_match("#video.yume.vn/(.*?)#s",$url));
	$is_zing = (preg_match("#video.zing.vn/([^/]+)#",$url,$id_sr));
	$is_zing1 = (preg_match("#video.zing.vn/video/clip/([^/]+)#",$url,$id_sr));	
	$is_veoh = (preg_match("#veoh.com/videos/(.*?)#s",$url));
	$is_veoh1 = (preg_match("#veoh.com/browse/videos/category/([^/]+)/watch/(.*?)#s",$url));
	$is_megavideo = (preg_match("#megavideo.com/\?v=(.*?)#s", $url,$id_sr));
	$is_megavideo_url = (preg_match("#megavideo.com/v/([^?]+)#",$url));
	$is_baamboo = (preg_match("#video.baamboo.com/watch/([0-9]+)/video/([^/]+)/(.*?)#",$url,$idvideo_baamboo));
	$is_livevideo = (preg_match("#livevideo.com/video/([^/]+)/(.*?)#",$url,$idvideo_live));
	$is_vidd = (preg_match("#viddler.com/([^/]+)#",$url,$id_sr));
	$is_vtv = preg_match("/^mms:\/\/+[a-zA-Z0-9\.]+(.*?)(VTV|VTC|HTV|dn1|dn2)+(.*?)/i",$url);
	$is_badongo = (preg_match("#badongo.com/vid/(.*?)#s",$url));
	$is_sendspace = (preg_match("#sendspace.com/file/(.*?)#s",$url));
	$is_goclip = (preg_match("#clips.go.vn/(.*?)#s",$url));
	$is_twitvid = (preg_match("#twitvid.com/(.*?)#s", $url));
	$is_olala = (preg_match("#timvui.vn/player/(.*?)#s",$url));
    $is_banbe= (preg_match("#banbe.net/([^/]+)#",$url,$id_sr));
	if ($is_googleVideo || $is_googleVideo1 || $is_baamboo) $type = 2;
	elseif (in_array($ext,$movie_arr) || $is_vtv) $type = 3;
	elseif ($is_youtube || $is_youtube1 || $is_youtube2) $type = 4;
	elseif ($is_tamtay || $is_tamtay1 || $idvideo_tamtay || $idvideo_tamtay2 || $is_tamtay_url1 || $is_tamtay_url2) $type = 7;
	elseif ($is_megavideo || $is_megavideo_url) $type = 6;
	elseif ($is_timnhanh) $type = 8;
	elseif ($ext == 'divx') $type = 9;
	elseif ($is_zing1) $type = 10;
	elseif ($is_clipvn || $is_clipvn1) $type = 11;
	elseif ($is_videozer || $is_videozer1) $type = 12;
	elseif ($is_veoh || $is_veoh1) $type = 13;
	elseif ($is_zing) $type = 14;
	elseif ($is_myspace) $type = 15;
	elseif ($is_daily || $is_daily1) $type = 16;
	elseif ($is_vidd) $type = 17;
	elseif ($is_movshare) $type = 18;
	elseif ($is_badongo) $type = 19;
	elseif ($is_nhaccuatui) $type = 20;
	elseif ($is_2shared || $is_2shared1) $type = 21;
	elseif ($is_4shared || $is_4shared1 || $is_4shared2) $type = 22;
	elseif ($is_sendspace) $type = 23;
	elseif ($is_vidxden) $type = 24;
	elseif ($is_olala) $type = 26;
	elseif ($is_mediafire) $type = 27;
	elseif ($is_zippyshare) $type = 28;
	elseif ($is_novamov) $type = 29;
	elseif ($is_cyworld || $is_cyworld1 || $is_cyworld2) $type = 30;
	elseif ($is_sharevnn) $type = 31;
	elseif ($is_megafun || $is_megafun1) $type = 32;
	elseif ($is_videobb) $type = 33;
	elseif ($is_gdatayoutube || $is_gdata) $type = 34;
	elseif ($is_speedyshare) $type = 35;
	elseif ($is_vidbux) $type = 40;
	elseif ($is_goclip) $type = 41;
	elseif ($is_twitvid) $type = 42;
	elseif ($is_picas) $type = 43;
	elseif ($is_seeon) $type = 44;
	elseif ($is_videozer2) $type = 45;
	elseif ($is_banbe) $type = 46;
	elseif (!$type) $type = 1;
    return $type;
}
function acp_local($local = 0, $other = false) {
    global $mysql, $tb_prefix;
    if($other) {
        if ($other == 'main') $other = ' onchange="check_local(this.value)"';
        elseif(is_numeric($other)) $other = '['.$other.'] id=local_url['.$other.']';
    }
    $html = "<select name=local_url".$other.">".
	$html .= "<option value=0".(($local == 0 && !$other)?" selected":'').">NO LOCAL</option>";
    $q = $mysql->query("SELECT * FROM ".$tb_prefix."local ORDER BY local_id ASC");
    while ($r = $mysql->fetch_array($q)) { 
    $html.= "<option value=".$r['local_id']."".(($local==$r['local_id'])?' selected':'').">".$r['local_name']."</option>";
    }
    "</select>";
    return $html;
}  

function admin_emotions_replace($s) {
	$emotions = emotions_array();
	foreach ($emotions as $a => $b) {
		$x = array();
		if (is_array($b)) {
			for ($i=0;$i<count($b);$i++) {
				$b[$i] = htmlchars($b[$i]);
				$x[] = $b[$i];
				$v = strtolower($b[$i]);
				if ($v != $b[$i]) $x[] = $v;
				}
		}
		else {
			$b = htmlchars($b);
			$x[] = $b;
			$v = strtolower($b);
			if ($v != $b) $x[] = $v;
			}
		$p = '';
		for ($u=0;$u<strlen($x[0]);$u++) {
			$ord = ord($x[0][$u]);
			if ($ord < 65 && $ord > 90) $p .= '&#'.$ord.';';
			else $p .= $x[0][$u];
		}
		$s = str_replace($x,'<img src=../images/emoticons/'.$a.'.gif>',$s);  
	}
	return $s;
}


function set_type($file_type) {
	$html = "<select name=file_type>".
		"<option value=0".(($file_type==0)?' selected':'').">DEFAULT</option>".
		"<option value=1".(($file_type==1)?' selected':'').">OTHER</option>".
		"<option value=31".(($file_type==31)?' selected':'').">Playlis YOUTUBE</option>".
		"<option value=42".(($file_type==42)?' selected':'').">MEDIAFIRE VIDEO</option>".
		"<option value=30".(($file_type==30)?' selected':'').">DANVIP IFRAME</option>".
                                "<option value=33".(($file_type==33)?' selected':'').">NOVAMOV IFRAME</option>".
 		"<option value=32".(($file_type==32)?' selected':'').">DOWNLOAD</option>".
		"<option value=2".(($file_type==2)?' selected':'').">FLASH</option>".
		"<option value=3".(($file_type==3)?' selected':'').">VIDEO</option>".
		"<option value=4".(($file_type==4)?' selected':'').">YOUTUBE</option>".
		"<option value=5".(($file_type==5)?' selected':'').">FLV</option>".
		"<option value=6".(($file_type==6)?' selected':'').">MEGAVIDEO</option>".
		"<option value=7".(($file_type==7)?' selected':'').">TAMTAY.VN</option>".
		"<option value=8".(($file_type==8)?' selected':'').">TIMNHANH.VN</option>".
		"<option value=10".(($file_type==10)?' selected':'').">CHACHA.VN</option>".
		"<option value=9".(($file_type==9)?' selected':'').">DIVX</option>".
		"<option value=11".(($file_type==11)?' selected':'').">CLIP.VN</option>".
		"<option value=12".(($file_type==12)?' selected':'').">BLOG.COM.VN</option>";
		"<option value=19".(($file_type==19)?' selected':'').">BADONGO</option>";
                             
		"<option value=25".(($file_type==25)?' selected':'').">SENDSPACE</option>";

		$html .= "</select>";
	return $html;
}

function admin_viewpages($ttrow,$n,$pg){
global $link;
$link = preg_replace("#&pg=([0-9]{1,})#si","",$link);
$html="<table valign=bottom cellpadding=2 cellspacing=2 align=center>";
$html.="<tr><td align=justify>";
$pgt = $pg-1;
if ($pg<>1) $html.="<a class=pagelink href=$link onfocus=this.blur() title ='Xem trang đầu'><b>&laquo;&laquo;</b></a> <a class=pagelink href=$link&pg=$pgt onfocus=this.blur() title='Xem trang trước'><b>&laquo;</b></a> ";
for($l = 0; $l < $ttrow/$n; $l++) {
$m = $l+1;
if($m == $pg) $html .= "<a onfocus=this.blur() class=pagecurrent>$m</a> ";
else $html .= "<a onfocus=this.blur() href=$link&pg=$m title='Xem trang $m' class=pagelink>$m</a> ";
}
$pgs = $pg+1;
if ($pg<>$m) $html.="<a class=pagelink href=$link&pg=$pgs onfocus=this.blur() title='Xem trang kế tiếp'><b>&raquo;</b></a> <a class=pagelink href=$link&pg=$m onfocus=this.blur() title='Xem trang cuối'><b>&raquo;&raquo;</b></a> ";
$html.="</td></tr></table>";
return $html;
}

function acp_quick_add_film_form() {
	$html = "<table cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">	
	<tr>
	<td width=\"40%\" align=\"right\"><b>NAME</b></td>
	<td><input name=\"new_film\" size=\"50\"></td>
    </tr>
    <tr>
	<td width=\"40%\" align=\"right\"><b>NAME REAL</b></td>
	<td><input name=\"name_real\" size=\"50\"></td>
    </tr>
	<tr>
	<td width=\"40%\" align=\"right\"><b>IMG</b></td>
	<td class=fr_2><input name=\"upload_img\" size=\"37\" type=\"file\"><BR /><BR />
	    <input name=\"url_img\" size=\"49\"></td>
    </tr>
	<tr>
	<td width=\"40%\" align=\"right\"><b>DIRECTOR</b></td>
	<td><input name=\"director\" size=\"50\"></td>
    </tr>
	<tr>
	<td width=\"40%\" align=\"right\"><b>ACTOR</b></td>
	<td><input name=\"actor\" size=\"50\"></td>
    </tr>
	<tr>
	<td width=\"40%\" align=\"right\"><b>PRODUCER</b></td>
	<td><input name=\"area\" size=\"50\"></td>
    </tr>
	<tr>
	<td width=\"40%\" align=\"right\"><b>ISSUE DAY</b></td>
	<td><input name=\"year\" size=\"50\"></td>
    </tr>
	<tr>
	<td width=\"40%\" align=\"right\"><b>TIME</b></td>
	<td><input name=\"time\" size=\"50\"></td>
    </tr>
	<tr>
	<td width=\"40%\" align=\"right\"><b>CATEGORY</b></td>
	<td>".acp_cat()."</td>
    </tr>
	<tr>
	<td colspan=\"2\" align=\"center\" style=\"padding-top:15px;\"><textarea name=\"info\" id=\"info\" cols=\"100\" rows=\"15\">    </textarea>
    <script language=\"JavaScript\">generate_wysiwyg('info');</script></td>
    </tr>
	</table>";
	return $html;
}

function acp_quick_add_film($new_film,$name_real,$new_film_img,$actor,$year,$time,$area,$director,$cat,$info,$country) {
	global $mysql, $tb_prefix;
	$q = $mysql->query("SELECT film_id FROM ".$tb_prefix."film WHERE film_name = '".UNIstr($new_film)."'");
	if ($mysql->num_rows($q)) {
		$r = $mysql->fetch_array($q);
		$film = $r[0];
		if($r['film_img'] == ' ')
	    $mysql->query("UPDATE ".$tb_prefix."film SET film_img = '".$new_film_img."' WHERE film_name = '".UNIstr($new_film)."'");
        elseif($r['film_name_real'] == ' ')
	    $mysql->query("UPDATE ".$tb_prefix."film SET film_name_real = '".$name_real."' WHERE film_name = '".UNIstr($new_film)."'");
	}
	else {
	    $mysql->query("INSERT INTO ".$tb_prefix."film (film_name,film_name_real,film_name_ascii,film_img,film_actor,film_year,film_time,film_area,film_director,film_cat,film_info,film_country) VALUES ('".UNIstr($new_film)."','".UNIstr($name_real)."','".strtolower(get_ascii($new_film))."','".$new_film_img."','".$actor."','".$year."','".$time."','".$area."','".$director."','".$cat."','".$info."','".$country."')");
		$film = $mysql->insert_id();
	}
	return $film;
}

function acp_film($id = 0, $add = false) {
	global $mysql,$tb_prefix;
	$q = $mysql->query("SELECT * FROM ".$tb_prefix."film ORDER BY film_name_ascii ASC");
	$html = "<select name=film>";
	if ($add) $html .= "<option value=dont_edit".(($id == 0)?" selected":'').">Không sửa</option>";
	while ($r = $mysql->fetch_array($q)) {
		$html .= "<option value=".$r['film_id'].(($id == $r['film_id'])?" selected":'').">".$r['film_name']."</option>";
	}
	$html .= "</select>";
	return $html;
}

function acp_cat($id = 0, $add = false) {
	global $mysql,$tb_prefix;
	$q = $mysql->query("SELECT * FROM ".$tb_prefix."cat ORDER BY cat_order ASC");
	$html = "<select name=cat>";
	if ($add) $html .= "<option value=dont_edit".(($id == 0)?" selected":'').">Không sửa</option>";
		while ($r = $mysql->fetch_array($q)) {
		$html .= "<option value=".$r['cat_id'].(($id == $r['cat_id'])?" selected":'').">- ".$r['cat_name']."</option>";
		}
	$html .= "</select>";
	return $html;
}

function acp_country($id = 0, $add = false) {
	global $mysql,$tb_prefix;
	$q = $mysql->query("SELECT * FROM ".$tb_prefix."country ORDER BY country_order ASC");
	$html = "<select name=country>";
	if ($add) $html .= "<option value=dont_edit".(($id == 0)?" selected":'').">Không sửa</option>";
		while ($r = $mysql->fetch_array($q)) {
		$html .= "<option value=".$r['country_id'].(($id == $r['country_id'])?" selected":'').">- ".$r['country_name']."</option>";
		}
	$html .= "</select>";
	return $html;
}

function acp_user_level($lv) {
	$html = "<select name=level>".
		"<option value=2".(($lv==2)?' selected':'').">Moderator</option>".
		"<option value=3".(($lv==3)?' selected':'').">Admin</option>".
	"</select>";
	return $html;
}

function acp_get_mod_permission() {
	global $mysql, $tb_prefix,$config_arr;	
	$permission_list = array(
		'add_cat',		
		'edit_cat',
		'del_cat',		
		'add_film',
		'edit_film',		
		'del_film',
		'add_link',
		'edit_link',		
		'del_link',
		'add_country',
	);	
	$per = $config_arr['cf_permission'];
	$per = decbin($per);
	$len = count($permission_list);
	while (strlen($per) < $len) $per = '0'.$per;
	
	for ($i=0;$i<$len;$i++) $arr[$permission_list[$i]] = $per[$i];
	return $arr;
	
}

function acp_check_permission($t) {
	global $level,$mod_permission;
	if ($level == 2 && !$mod_permission[$t]) die('<center>BẠN KHÔNG ĐỦ QUYỀN TRUY CẬP VÀO TRANG NÀY</center>');
}
?>